<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/15
 * Time: 15:35
 */
//引用DbTools.php和common.php
include_once '../tools/DbTools.php';
include_once '../tools/common.php';
//开启SESSION
session_start();
//使用getLoginStatus方法
$is_login = getLoginStatus();
//通过getLoginStatus方法判断登录状态
if(!$is_login) {
    echo '尚未登陆，<a href="../user/loginUi.php">请先登录</a>';
    die;
}else{
    //获取transfer传输进来的accounts值
    $accounts = $_POST['accounts'];
    //获取transfer传输进来的moneyInCardNo值
    $moneyInCardNo = $_POST['moneyInCardNo'];
    //判断如果$accounts值为空或者小于等于0则表示传输进来的$accounts值有误
    if(empty($accounts) || $accounts<=0){
        echo '转账金额有误';
        die;
    }
    //判断如果$moneyInCardNo值为空则表示传输进来的$moneyInCardNo值有误
    if(empty($moneyInCardNo)){
        echo '转账卡号有误';
        die;
    }
    //通过根据卡号获取卡ID方法获取到$moneyInCardId
    $moneyInCardId = getCardNoByCardId($moneyInCardNo);
    //通过SESSION获取到COOKIE中的数据
    $userinfo = $_SESSION[$_COOKIE['Token']];
    //不能进行自我转账，即同一张卡进行转账交易
    if($moneyInCardId == $userinfo['CardId']){
        echo '无法转账';
        die;
    }
    //通过转账方法进行转账
    $result = transferMoney($userinfo['CardId'],$moneyInCardId,$accounts);
    //判断$result
    if($result['status']){
        echo '转账成功，<a href="transfer.php">再次转账</a>';
    }else{
        echo '转账失败:'.$result['message'];
    }
}